package model;

import lombok.Data;

import java.time.LocalDateTime;

@Data
public class R<T> {
    //状态码
    private Integer code;
    //提示信息
    private String msg;
    //数据
    private T data;
    //接口请求时间
    private LocalDateTime timestamp;

    public R() {
        this.timestamp = LocalDateTime.now();
    }

    public static <T> R<T> success(T data) {
        R<T> r = new R<>();
        r.setCode(200);
        r.setMsg("success");
        r.setData(data);
        return r;
    }

    public static <T> R<T> error(int code, String msg) {
        R<T> r = new R<>();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(null);
        return r;
    }
}

